<template>
  <div class="detail">
    <div>
      <header class="detail-header">
        <i class="icon-return iconfont" @click="returnPage"></i>
        <h1>商品详情</h1>
        <p></p>
      </header>

      <section class="goods-section">
        <div class="pic swiper-container focus">
          <ul class="swiper-wrapper">
            <li class="swiper-slide"><img src="../assets/img-detail/1.jpg" alt=""></li>
            <li class="swiper-slide"><img src="../assets/img-detail/2.jpg" alt=""></li>
            <li class="swiper-slide"><img src="../assets/img-detail/3.jpg" alt=""></li>
            <li class="swiper-slide"><img src="../assets/img-detail/4.jpg" alt=""></li>
          </ul>
        </div>
        <ul class="cur">
          <li class="on"></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
        <div class="goodsInfo">
          <h1>{{goodsObj.title}}</h1>
          <p>{{goodsObj.explains}}</p>
          <ul>
            <li>
              本店售价:
              <b class="price">￥{{goodsObj.price}}</b>
              <s>￥{{goodsObj.oldprice}}</s>
            </li>
            <li>
              本商品正在进行:
              <b>{{goodsObj.active}}</b>
              购物金额满500元，省100元
            </li>
            <li>
              月销量:
              <b>{{goodsObj.sale}}</b>件
            </li>
          </ul>
        </div>
        <div class="wrap">
          <div class="goodsBuy radius5">
            <label class="info clearfix">
              请选择
              <span>数量/产品尺寸/配送方式/制作类型</span>
              <i class="iconfont icon-packup"></i>
            </label>
          </div>
          <ul class="ul1">
            <li>
              商品总价：
              <b class="price">￥{{total}}</b>
            </li>
          </ul>
          <ul class="ul2 clearfix">
            <li>
              <h2>数量：</h2>
              <ul class="items catt">
                <li>
                  <a class="cattsel" href="javascript:;">1-20
                    <i></i>
                  </a>
                </li>
                <li>
                  <a href="javascript:;">1-20</a>
                </li>
                <li>
                  <a href="javascript:;">1-20</a>
                </li>
              </ul>
            </li>
            <li>
              <h2>产品尺寸：</h2>
              <ul class="items catt">
                <li>
                  <a class="cattsel" href="javascript:;">默认尺寸
                    <i></i>
                  </a>

                </li>
                <li>
                  <a href="javascript:;">定制尺寸</a>
                </li>
              </ul>
            </li>
            <li>
              <h2>配送方式：</h2>
              <ul class="items catt">
                <li>
                  <a class="cattsel" href="javascript:;">全国包邮
                    <i></i>
                  </a>
                </li>
                <li>
                  <a href="javascript:;">普通快递</a>
                </li>
              </ul>
            </li>
            <li>
              <h2>制作类型：</h2>
              <ul class="items catt">
                <li>
                  <a class="cattsel" href="javascript:;">无稿件(设计+制作)
                    <i></i>
                  </a>
                </li>
                <br/>
                <li>
                  <a href="javascript:;">自有稿件(制作)</a>
                </li>
              </ul>
            </li>
          </ul>
          <ul class="quantity clearfix">
            <h2>数量：</h2>
            <div class="items">
              <span class="ui-number radius5 flx">
                <button @click="decrease" type="button" class="decrease radius5">-</button>
                <input v-model="num" class="num" id="goods_number" type="text">
                <button @click="increase" type="button" class="decrease radius5">+</button>
              </span>
            </div>
            <p class="kc">库存:
              <span class="shows_number">9999件</span>
            </p>
          </ul>
        </div>
        <div class="guarantee">微信支付商家,正品保证,假一罚三,七天无条件退换货。</div>
        <div class="s-detail">
          <mu-tabs class="header" :value.sync="active" inverse color="secondary" text-color="rgba(0, 0, 0, .54)" full-width>
            <mu-tab class="current">详情</mu-tab>
            <mu-tab>评价(0)</mu-tab>
            <mu-tab>热销</mu-tab>
          </mu-tabs>
          <div class="demo-text" v-if="active === 0">
            <table>
              <tr>
                <td class="tit">产品名称 :</td>
                <td class="proTit">广告纸杯</td>
              </tr>
            </table>
            <div class="imgs">
              <img src="../assets/img-detail/1.jpg">
              <img src="../assets/img-detail/2.jpg">
              <img src="../assets/img-detail/3.jpg">
            </div>
          </div>
          <div class="demo-text" v-if="active === 1">
            <div class="pages">
              总计 0 个记录，共 1 页。
              <span>
                <a href="javascript:;">上一页</a>
                <a href="javascript:;">下一页</a>
              </span>
            </div>
            <div class="commentsList radius5">
              <form>
                <table width="100%" align="center">
                  <tbody>
                    <tr>
                      <td>
                        用户名：匿名用户 </td>
                    </tr>
                    <tr>
                      <td>
                        <input name="comment_rank" type="radio" value="5" checked="checked" id="comment_rank5"> 非常好
                        <input name="comment_rank" type="radio" value="4" id="comment_rank4"> 很好
                        <input name="comment_rank" type="radio" value="3" id="comment_rank3"> 一般
                        <input name="comment_rank" type="radio" value="2" id="comment_rank2"> 不行
                        <input name="comment_rank" type="radio" value="1" id="comment_rank1"> 很差
                      </td>
                    </tr>
                    <tr>
                      <td>
                        <input placeholder="E-mail" type="text" name="email" id="email" maxlength="100" value="" class="inputBg">
                      </td>
                    </tr>
                    <tr>
                      <td>
                        <textarea placeholder="评论内容" name="content" class="inputBg2" style="height:4rem"></textarea>
                        <input type="hidden" name="cmt_type" value="0">
                        <input type="hidden" name="id" value="34">
                      </td>
                    </tr>

                    <tr>
                      <td><input type="submit" name="submit" value="提交评论" class="c-btn3"></td>
                    </tr>
                  </tbody>
                </table>
              </form>
            </div>
          </div>
          <div class="demo-text" style="height:300px" v-if="active === 2"></div>
        </div>
        <div class="content-footer">
          <div id="content" class="footer">
            <div class="in">
              <div class="search_box">
                <form method="post" action="search.php" name="searchForm" id="searchForm_id">
                  <input name="keywords" type="text" id="keywordfoot">
                  <i class="iconfont icon-search"></i>
                </form>
              </div>
              <a href="./" class="homeBtn">
                <span class="iconfont icon-homepage_fill"> </span>
              </a>
              <a href="#top" class="gotop">
                <span class="iconfont icon-packup"> </span>
                <p> TOP </p>
              </a>
            </div>
            <p class="link region">
              <a href="./"> 返回首页 </a>
              <a href="flow.php"> 购物车 </a>
              <a href="user.php"> 会员中心 </a>
              <a href="ectouch.php?act=contact"> 联系我们 </a>
            </p>
            <p class="region">© 2005-2019 任印网－联合创想企业旗下品牌 版权所有，并保留所有权利。 </p>
            <div class="favLink region">
              <a href="http://www.xpkj.net"> powered by 众合网络 </a>
            </div>
          </div>
        </div>
      </section>

      <footer class="detail-footer">
        <div @click="toHome" class="w50">
          <i class="icon-homepage iconfont"></i>
          首页
        </div>
        <div @click="goToShopCart" class="w50">
          <i class="icon-publishgoods_fill iconfont"></i>
          购物车
        </div>
        <a @click="pushShopsCart" class="btn car">加入购物车</a>
        <a class="btn">立刻购买</a>
      </footer>

    </div>
    <!-- 购物车弹框 -->
    <div class="dialog" v-if="addShopsCart">
      <div class="blog">
        <div class="tit">
          <h4>商品加入购物车</h4>
          <i @click="closeBlog" class="iconfont icon-close"></i>
        </div>
        <div class="main">
          <div class="left"> <img width="115" height="115" src="../assets/img/p2.jpg"> </div>
          <div class="right">
            <p>{{goodsObj.title}}</p>
            <span> 加入数量：
              <b id="cartNum">{{num}}</b>
            </span>
            <span> 总计金额：
              <b id="cartPrice">￥
                <span>{{total}}</span>
              </b>
            </span>
          </div>
        </div>
        <div class="popbtn">
          <span @click="goonShopping" class="bnt1 radius5">继续购物</span>
          <span @click="goToJS" class="bnt2 radius5">去结算</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/dist/css/swiper.css'
import { createNamespacedHelpers } from 'vuex'
const { mapState, mapMutations, mapActions } = createNamespacedHelpers('detail')
import ss from '../Plug/session.js'
export default {
  name: 'Detail',
  data() {
    return {
      active: 0,
      goodsObj: {},
      goodsID: '',
      num: 1,
      total: '',
      addShopsCart: false,
      uid: ''
    }
  },
  mounted() {
    var myswiper = new Swiper('.swiper-container', {
      autoplay: true,
      speed: 300,
      loop: true
    })
    this.getCurrentGoods()
    this.goodsID = this.$route.params.id
    this.uid = ss.get().id
  },
  methods: {
    ...mapActions(['getShopsData', 'submitOrder']),
    pushShopsCart() {
      this.addShopsCart = true
      let obj = {
        uid: this.uid || 1,
        price: this.goodsObj.price,
        number: this.num,
        total: this.total,
        attr: '',
        shopid: this.goodsID,
        shoptitle: this.goodsObj.title
        // uid:用户的ID
        // price：商品单价
        // number：商品数量
        // total：商品总价
        // attr：商品属性
        // shopid:商品ID
        // shoptitle：商品名称
      }
      this.submitOrder(obj).then(data => {
        console.log(data)
      })
    },
    closeBlog() {
      this.addShopsCart = false
    },
    goToJS() {
      this.$router.push('/shopping')
    },
    goonShopping() {
      this.addShopsCart = false
    },
    goToShopCart() {
      this.$router.push('/shopping')
    },
    increase() {
      this.num++
      this.total = this.goodsObj.price * this.num
    },
    decrease() {
      if (this.num == 1) {
        return
      }
      this.num--
      this.total = this.goodsObj.price * this.num
    },
    getCurrentGoods() {
      this.getShopsData().then(data => {
        let arr = data
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].id == this.goodsID) {
            this.goodsObj = arr[i]
            this.total = this.goodsObj.price * this.num
            // console.log(this.total)
          }
        }
      })
    },
    returnPage() {
      this.$router.back(-1)
    },
    toHome() {
      this.$router.push('/')
    }
  }
}
</script>

<style scoped>
.dialog {
  background-color: rgba(0, 0, 0, 0.4);
  width: 100%;
  height: 100%;
  position: fixed;
  z-index: 666;
}
.blog {
  background-color: #efefef;
  position: fixed;
  z-index: 100010;
  left: 0;
  bottom: 0;
  height: auto;
  width: 90%;
  margin: 5%;
}
.blog .tit {
  background-color: #ff3838;
  line-height: 32px;
  height: 32px;
  text-align: center;
  position: relative;
}
.blog .tit h4 {
  font-size: 13px;
  color: #fff;
  font-weight: normal;
}
.blog .tit i {
  position: absolute;
  right: 0;
  top: 0;
  width: 32px;
  font-size: 20px;
  color: #fff;
  font-weight: bold;
}
.blog .main {
  display: table;
  border-collapse: collapse;
  width: 100%;
}
.blog .left {
  display: table-cell;
  width: 40%;
  padding: 4.8px 0;
  text-align: center;
  vertical-align: top;
}
.blog .left img {
  border: 0;
  margin: 0 5px;
}
.blog .right {
  display: table-cell;
  width: 60%;
  padding: 4.8px 0;
  text-align: left;
  vertical-align: top;
}
.blog .right p {
  display: block;
  height: 32px;
  color: #333;
  line-height: 16px;
  padding-bottom: 12.8px;
  padding-right: 12.8px;
}
.blog .right span {
  color: #666;
  display: block;
  margin-bottom: 6.4px;
  font-size: 13px;
}
.blog .popbtn {
  font-size: 13px;
  height: 32px;
  width: auto;
  padding: 8px 8px;
  background: #e1e1e1;
  display: -webkit-box;
  box-sizing: content-box !important;
}
.blog .popbtn span {
  background: #6bd0a2;
  height: 32px;
  line-height: 32px;
  text-align: center;
  display: block;
  width: 50%;
  color: #fff;
}
.blog .popbtn .bnt2 {
  margin-left: 8px;
  background: #ff3838;
  width: 47%;
}
body,
ul,
h1,
h2,
h3,
h4,
h5,
h6,
p,
button {
  margin: 0;
  padding: 0;
}
ul {
  list-style: none;
}
a {
  text-decoration: none;
  color: inherit;
}
input {
  outline: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
.clearfix:after,
.catt li:after {
  content: '';
  display: block;
  clear: both;
}

body {
  background: #ebeced;
}

/* 布局 */
html,
body,
.detail {
  height: 100%;
}

.detail {
  display: flex;
  flex-flow: column;
}

.detail-header {
  height: 48px;
  background: #ff3838;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.goods-section {
  flex-grow: 1;
  position: relative;
  top: 48px;
  margin-bottom: 50px;
}

.detail-footer {
  height: 50px;
  background: #ccc;
  position: fixed;
  bottom: 0;
  width: 100%;
  z-index: 2;
  display: flex;
}

/* 头部 */
.detail-header h1 {
  font-size: 18px;
  color: #fff;
  font-weight: normal;
}
.detail-header i {
  margin-left: 10px;
}
.detail-header p {
  margin-right: 10px;
}
.icon-return {
  display: inline-block;
  font-size: 20px;
  color: #fff;
  font-weight: bold;
}
/* 底部 */
.detail-footer ul {
  display: flex;
}
.w50 {
  display: flex;
  flex-flow: column;
  justify-content: center;
  align-items: center;
  width: 50px;
  height: 50px;
  font-size: 12px;
  background: #fff;
}

.icon-publishgoods_fill,
.icon-homepage {
  font-size: 25px !important;
}

.btn {
  background: #e4393c;
  color: #fff;
  display: block;
  float: left;
  font-size: 16px;
  height: 100%;
  line-height: 50px;
  text-align: center;
  width: 50%;
}
.car {
  background: #fe9303;
}
/* 内容 */
.pic,
.pic img {
  width: 100%;
  height: 320px;
  background: #ccc;
}
.cur {
  height: 32px;
  line-height: 32px;
  top: 2px;
  left: 0;
  right: 0;
  text-align: center;
}
.cur li.on {
  background: #ff3838;
}
.cur li {
  display: inline-block;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
  margin: 0 5px;
  width: 5px;
  height: 5px;
}
.cur {
  height: 32px;
  background: #fff;
  border-bottom: 1px solid #ccc;
}
.goodsInfo {
  background: #fff;
  position: relative;
}

.goodsInfo h1 {
  font-size: 16px;
  padding: 2px 0;
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  font-weight: normal;
}

.goodsInfo p {
  font-size: 12px;
  padding: 0 1px;
}

.goodsInfo ul,
.ul1 {
  padding: 4px 0;
  color: #999;
  font-size: 12px;
}

.goodsInfo ul > li {
  padding: 2px 0 3px;
  border-bottom: 1px solid #f3f3f3;
  margin-bottom: 3px;
}

.goodsInfo ul > li:last-child {
  margin: 0;
}

.goodsInfo .collect {
  top: -55px;
  right: 10px;
  position: absolute;
  background: #f8f8f8;
  padding: 1px 10px;
  border-radius: 20px;
}

.goodsInfo .collect i {
  font-size: 40px;
}

.price {
  color: #ff3838;
  font-size: 16px;
  font-weight: bold;
  padding: 0 3px;
  display: inline-block;
}

.goodsBuy {
  padding: 0 4px;
  margin: 6px 0;
  background: #fff;
}

.radius5 {
  border-radius: 5px;
  outline: none;
}

.info {
  font-size: 12px;
  display: block;
  color: #999;
  border-bottom: 1px solid #f3f3f3;
  padding: 4px 0 6px;
}

.goodsBuy .info span {
  color: #333;
  margin-left: 2px;
}

.goodsBuy .info i {
  float: right;
}

.ul1,
.ul2 {
  padding: 2px 4px;
}
.ul2 a {
  font-size: 12px;
}
.catt a {
  border: #c8c9cd 1px solid;
  border-radius: 5px;
  text-align: center;
  margin-right: 10px;
  margin-top: 6px;
  display: block;
  white-space: nowrap;
  color: #000;
  text-decoration: none;
  float: left;
  position: relative;
  cursor: pointer;
  padding: 6px 10px;
}

.ul2 h2,
.quantity h2 {
  font-size: 14px;
  color: #999;
  margin-bottom: 4px;
}

.ul2 li {
  padding: 0 2px 10px;
  float: left;
}

.catt a:focus {
  outline-style: none;
}

.catt a:hover {
  border: #f52648 1px solid;
  margin-top: 6px;
}

.catt .cattsel {
  border: #f70 1px solid;
  background-color: #fff;
}

.catt .cattsel i {
  background: url(../assets/img-detail/test.gif) no-repeat scroll right bottom
    transparent;
  bottom: 0;
  height: 16px;
  position: absolute;
  right: 0;
  width: 16px;
}

.quantity .ui-number {
  float: left;
  vertical-align: middle;
  border: 1px solid #e3e3e3;
  letter-spacing: 0;
  height: 36px;
  line-height: 36px;
  overflow: hidden;
}

.decrease {
  font-style: normal;
  font-size: 20px;
  font-weight: 700;
  border: 0;
  display: inline-block;
  width: 32px;
  height: 32px;
  background: #fafafa;
  text-align: center;
  color: #333;
  cursor: pointer;
}

.quantity .ui-number .num {
  width: 48px;
  height: 100%;
  border: 0;
  border-radius: 0;
  font-weight: 700px;
  text-align: center;
}

.quantity {
  padding: 0 0 10px 5px;
}

.kc {
  font-size: 12px;
  float: left;
  height: 32px;
  line-height: 36px;
  margin-left: 16px;
}

.guarantee {
  height: 32px;
  line-height: 32px;
  border-radius: 4px;
  background-size: 18px;
  margin-top: 0px;
  padding-left: 24px;
  font-size: 12px;
  background: #fffdce;
  margin-top: 10px;
}

.wrap {
  background: #fff;
  border-radius: 5px;
  margin: 15px 0;
}

.s-detail {
  margin-top: 15px;
}

.s-detail table {
  width: 100%;
}

.header {
  position: static;
  text-align: center;
  font-size: 12px;
  background-color: #eee;
  display: flex;
}

.s-detail ul li {
  background-color: #f5f5f5;
  color: #333;
  line-height: 38px;
  margin-right: 1px;
  border-top: 1px solid #f8f8f8;
  flex: 1;
  box-sizing: border-box;
}

.s-detail ul li.current {
  position: relative;
  background-color: #fff;
  border-top: 2px solid #ff3838;
}

.s-detail table td {
  border: 1px solid #e5e5e5;
  padding: 5px 10px;
  background-color: #fff;
  box-sizing: border-box;
  font-size: 12px;
}

.s-detail table td.tit {
  background-color: #f5f5f5;
  font-weight: bold;
  text-align: right;
  width: 25%;
}

.proTit {
  width: 75%px;
}

.imgs img {
  width: 100%;
  height: auto;
  display: block;
}

.s-detail .wrap {
  overflow: hidden;
}

.hidden {
  display: none;
}

.s-detail a {
  color: #333;
}

.pages {
  text-align: right;
  padding: 10px 4px;
  font-size: 14px;
}

.commentsList {
  background: #fff;
  padding: 8px;
  font-size: 12px;
}

.commentsList tr td {
  padding: 10px 0;
}

.inputBg {
  height: 38px;
  width: 94%;
  border: solid 1px #ddd;
  padding: 0 3%;
  color: #333;
  font-size: 12px;
  /* -webkit-border-radius: 0; */
  background: #fff;
}

.inputBg2 {
  width: 94%;
  border: solid 1px #ddd;
  padding: 3%;
  color: #333;
  font-size: 12px;
  /* -webkit-border-radius: 0; */
  -webkit-appearance: none;
  background: #fff;
}

.c-btn3 {
  color: #fff;
  border: 0;
  height: 40px;
  line-height: 40px;
  width: 100%;
  -webkit-box-flex: 1;
  display: block;
  -webkit-user-select: none;
  font-size: 14px;
  background: #ff3838;
  text-align: center;
}

.commentsList table tr td {
  border: 0;
}

/* 底部 */
.footer {
  padding: 0 9.6px 9.6px;
  color: #aaa;
  font-size: 9.6px;
  margin-top: 20px;
}

.footer .in {
  position: relative;
  height: 44.8px;
  margin: 0 -9.6px;
  padding: 0 56px;
  background-color: #b9b9b9;
}

.search_box {
  position: relative;
  top: 6.4px;
  width: 100%;
  background: #fff;
  border-radius: 20px;
  text-align: center;
}

form {
  display: block;
  margin: 0;
}

.search_box input {
  width: 85%;
  height: 32px;
  line-height: normal;
  border: none;
  font-size: 13px;
  outline: none;
}

.search_box i {
  font-size: 18px;
  position: absolute;
  top: 2px;
  right: 1px;
  width: 20px;
  height: 20px;
  border: none;
}

.footer .gotop,
.footer .homeBtn {
  background: #a1a1a1;
}

.homeBtn {
  left: 0;
}

.homeBtn,
.footer .gotop {
  position: absolute;
  top: 0;
  width: 44px;
  height: 44px;
  color: #fff;
  font-size: 11px;
}

.homeBtn span {
  font-size: 32px;
  position: absolute;
  left: 4.8px;
  top: 4.8px;
}

.footer .gotop {
  right: 0;
}

.footer .gotop,
.footer .homeBtn {
  background: #a1a1a1;
}

.footer .gotop span {
  font-size: 24px;
  position: absolute;
  left: 27%;
  top: 1.8px;
  width: 20px;
  height: 20px;
}

.footer .gotop p {
  position: absolute;
  bottom: 2.24px;
  left: 7.2px;
  width: 35px;
}

.footer .link {
  line-height: 16px;
  font-size: 11px;
  color: #1ca2e1;
}

.footer .link a {
  display: inline-block;
  margin-top: 4.8px;
  padding: 0 9.6px 0 4.8px;
  border-right: 1px solid #d5d5d5;
  color: #1ca2e1;
}

.footer .link a:last-child {
  border: none;
}

.footer .favLink,
.footer p {
  text-align: center;
  line-height: 20px;
}

.footer .favLink a {
  margin-right: 4.8px;
  color: #aaa;
}

.mu-tabs {
  margin-top: -20px;
}
</style>
